@extends('layouts.app')

@section('title', $address->id? '修改地址': '新增地址')
@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <div class="panel panel-default">
                    <div class="panel-heading">{{$address->id? '修改地址': '新增地址'}}</div>

                    <div class="panel-body">
                        @if($address->id)
                            {{--<form class="form-horizontal" method="POST" action="{{route('user_addresses.update',['address'=>$address->id])}}">--}}  {{-- ok 1 --}}
                            <form class="form-horizontal" method="POST" action="{{route('user_addresses.update',[$address->id])}}">                     {{-- ok 2 --}}
                            {{method_field('put')}}
                        @else
                            <form class="form-horizontal" method="POST" action="{{route('user_addresses.store')}}">
                        @endif
                            {{ csrf_field() }}
                            <p><br></p>

                            {{--<select-district></select-district>--}}

                            <select-district inline-template>
                                <div class="form-group{{ $errors->has('province')|| $errors->has('city')|| $errors->has('district') ? ' has-error' : '' }}">
                                    <label class="control-label col-md-4">请选择省市区</label>
                                    <div class="col-md-6"  >
                                        <div style="display:flex" id="china-area">
                                            <select-input :area="area" :name="'province'" :sun="'city'"     :value="'{{old('province')?: $address->province}}'"></select-input>
                                            <select-input :area="area" :name="'city'"     :sun="'district'" :value="'{{old('city')?: $address->city}}'"></select-input>
                                            <select-input :area="area" :name="'district'" :sun="''"         :value="'{{old('district')?: $address->district}}'"></select-input>
                                        </div>
                                        <span class="help-block">
                                            @if ($errors->has('province'))
                                                <strong>{{ $errors->first('province') }}</strong>
                                            @endif
                                            @if ($errors->has('city'))
                                                <strong>{{ $errors->first('city') }}</strong>
                                            @endif
                                            @if ($errors->has('district'))
                                                <strong>{{ $errors->first('district') }}</strong>
                                            @endif
                                        </span>
                                    </div>
                                </div>
                            </select-district>

                            @component('com.input',[
                                'obj'=>$address,
                                'errors'=>$errors,
                                'key'=>'address',
                                'text'=>'地址',
                                'placeholder'=>'例：xx路xx号，或：xx镇xx村xx号',
                                'required'=>false,
                            ])
                            @endcomponent

                            @component('com.input',[
                                'obj'=>$address,
                                'errors'=>$errors,
                                'key'=>'zip',
                                'text'=>'邮政编码',
                                'placeholder'=>'',
                                'required'=>false,
                            ])
                            @endcomponent

                            @component('com.input',[
                                'obj'=>$address,
                                'errors'=>$errors,
                                'key'=>'contact_name',
                                'text'=>'联系人',
                                'placeholder'=>'联系人的姓名',
                                'required'=>false,
                            ])
                            @endcomponent

                            @component('com.input',[
                                'obj'=>$address,
                                'errors'=>$errors,
                                'key'=>'contact_phone',
                                'text'=>'联系电话',
                                'placeholder'=>'手机号码',
                                'required'=>false,
                            ])
                            @endcomponent

                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-4">
                                    <button type="submit" class="btn btn-primary" id="submitbutton">
                                        提交
                                    </button>
                                </div>
                            </div>

                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection